package com.liuyongsheng.teafile.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * Swagger配置类，用于配置API文档生成
 */
@Configuration
@EnableSwagger2
@EnableWebMvc
public class CustomSwaggerConfig {

    @Value("${swagger.enabled:true}")
    private boolean swaggerEnabled;

    /**
     * 配置Swagger Docket
     * @return Swagger Docket实例，用于生成API文档
     */
    @Bean
    public Docket api() {
        return new Docket(DocumentationType.SWAGGER_2)
                .enable(swaggerEnabled)
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.liuyongsheng.teafile.controller"))
                .paths(PathSelectors.any())
                .build()
                .apiInfo(new ApiInfoBuilder()
                        .title("TeaFile文件上传服务API文档")
                        .version("1.0")
                        .description("1.支持任意文件上传。\n2.上传pdf自动转为图片。\n3.支持访问上传的文件。")
                        .build());
    }
}
